<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JSON数据展示</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }

        h1 {
            color: #333;
        }

        .card {
            display: flex;
            border: 1px solid #ccc;
            border-radius: 5px;
            padding: 10px;
            margin-bottom: 10px;
            max-height: 200px;
            overflow-y: auto;
        }

        .card h2 {
            margin-top: 0;
        }

        .card ul {
            list-style-type: none;
            padding: 0;
            margin-right: 20px;
        }

        .card li {
            margin-bottom: 5px;
        }

        .markdown {
            width: 50%;
            flex-shrink: 0;
            height: 350;
            overflow-y: auto;
        }
    </style>
    <base target="_blank">
        </base>
</head>

<body>
    <h1>JSON数据展示</h1>

    <div id="json-cards"></div>

    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <script>
        let jsonData = [];

        function loadJsonData() {
            fetch('final.json')
                .then(response => response.json())
                .then(data => {
                    jsonData = data;
                    displayJsonData();
                })
                .catch(error => console.error('Error loading JSON data:', error));
        }

        function displayJsonData() {
            const jsonCards = document.getElementById('json-cards');
            jsonCards.innerHTML = '';

            jsonData.forEach((item, index) => {
                const card = document.createElement('div');
                card.classList.add('card');

                // const title = document.createElement('h2');
                // title.textContent = `Item ${index + 1}`;
                // card.appendChild(title);

                const jsonList = document.createElement('ul');
                for (const key in item) {
                    if (item.hasOwnProperty(key)) {
                        const listItem = document.createElement('li');
                        if (key === 'aiResult') {
                            const markdownDiv = document.createElement('div');
                            markdownDiv.classList.add('markdown');
                            markdownDiv.innerHTML = marked.parse(item[key]);
                            card.appendChild(markdownDiv);
                        } else {
                            listItem.textContent = `${key}: ${item[key]}`;
                            jsonList.appendChild(listItem);
                        }
                    }
                }
                const atag = document.createElement('a');
                atag.href = `https://www.xiaohongshu.com/explore/${item.id}?xsec_token=${item.xsec_token}&xsec_source=pc_feed`
                atag.textContent = '小红书链接'

                jsonList.appendChild(atag)
                card.appendChild(jsonList);

                jsonCards.appendChild(card);
            });
        }

        loadJsonData();
    </script>
</body>

</html>